< previous page page_159 next page >

Page 159
e10a6a0a59f035e870d90cca05b85fce.gif
'Set the printer's scale properties so it will
' print the object as large as possible, centered
' in the printable area.
Private Sub SetLargePrinterScale(obj As Object)
Dim owid As Single
Dim ohgt As Single
Dim pwid As Single
Dim phgt As Single
Dim xmid As Single
Dim ymid As Single
Dim s As Single

    ' Get the object's size in twips.
    owid = obj.ScaleX(obj.ScaleWidth, obj.ScaleMode, vbTwips)
    ohgt = obj.ScaleY(obj.ScaleHeight, obj.ScaleMode, vbTwips)

    ' Get the printer's size in twips.
    pwid = Printer.ScaleX(Printer.ScaleWidth, _
        Printer.ScaleMode, vbTwips)
    phgt = Printer.ScaleY(Printer.ScaleHeight, _
        Printer.ScaleMode, vbTwips)

    ' Compare the object and printer aspect ratios.
    If ohgt / owid > phgt / pwid Then
        ' The object is relatively tall and thin.
        ' Use the printer's whole height.
        s = phgt / ohgt ' This is the scale factor.
    Else
        ' The object is relatively short and wide.
        ' Use the printer's whole width.
        s = pwid / owid ' This is the scale factor.
    End If 

    ' Convert the printer's dimensions into scaled
    ' object coordinates.
    pwid = obj.ScaleX(pwid, vbTwips, obj.ScaleMode) / s
    phgt = obj.ScaleY(phgt, vbTwips, obj.ScaleMode) / s

    ' See where the center should be.
    xmid = obj.ScaleLeft + obj.ScaleWidth / 2
    ymid = obj.ScaleTop + obj.ScaleHeight / 2

    ' Pass the coordinates of the upper left and
    ' lower right corners into the Scale method.
    Printer.Scale _
        (xmid - pwid / 2, ymid - phgt / 2)- _ 
        (xmid + pwid / 2, ymid + phgt / 2) 
End Sub
Example program FrmScale is similar to program FrmPrint except it uses the SetLargePrinterScale subroutine to make its picture as large as possible before printing it.

 
< previous page page_159 next page >